package org.example.demo_xiaowuz.config;


import lombok.extern.slf4j.Slf4j;
import org.example.demo_xiaowuz.model.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
//@ResponseBody
//@ControllerAdvice
@RestControllerAdvice
public class ErrorAdvice {
    @ExceptionHandler(ArithmeticException.class)
    public Result handler1(Exception e){
        log.error("发生ArithmeticException, e:", e);
        return Result.fail("发生算术异常: "+e.getMessage());
    }
    @ExceptionHandler(NullPointerException.class)
    public Result handler2(Exception e){
        log.error("发生NullPointerException, e:", e);
        return Result.fail("发生空指针异常: "+e.getMessage());
    }
    @ExceptionHandler(Exception.class)
    public Result handler3(Exception e){
        log.error("发生异常, e:", e);
        return Result.fail("发生异常: "+ e.getMessage());
    }
}
